﻿/* QF classbuilder for Enlib */
using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Logging;

#region SYS_UserEmpl实体类
public class SYS_UserEmpl
{
	private string m_UserName;
	private string m_EmplID;
	
	public SYS_UserEmpl ()
	{
		m_UserName="";
		m_EmplID="";
	}
	
	public string UserName
	{
		get{return m_UserName;}
		set{m_UserName=value;}
	}
	public string EmplID
	{
		get{return m_EmplID;}
		set{m_EmplID=value;}
	}
}
#endregion

#region SYS_UserEmpl管理类
public partial class LogicLayer
{
	public bool AddSYS_UserEmpl(SYS_UserEmpl theSYS_UserEmpl)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "insert into SYS_UserEmpl (UserName,EmplID) values (@UserName,@EmplID)";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@UserName", DbType.String, theSYS_UserEmpl.UserName);
			db.AddInParameter(cmd, "@EmplID", DbType.String, theSYS_UserEmpl.EmplID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("AddSYS_UserEmpl:" + ex.Message );
			return false;
		}
	}
	
	public SYS_UserEmpl GetSYS_UserEmplFromDataReader(IDataReader dataReader)
	{
		try
		{
			SYS_UserEmpl result = new SYS_UserEmpl();
			
			if (dataReader["UserName"] != null && dataReader["UserName"] != System.DBNull.Value )
				result.UserName = (string)dataReader["UserName"];
			if (dataReader["EmplID"] != null && dataReader["EmplID"] != System.DBNull.Value )
				result.EmplID = (string)dataReader["EmplID"];
			
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetReaderSYS_UserEmpl:" + ex.Message);
			return null;
		}
	}
	
	public SYS_UserEmpl GetSYS_UserEmpl()
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * From SYS_UserEmpl where ";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			SYS_UserEmpl result = null;
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				if (dataReader.Read())
				{
					result = GetSYS_UserEmplFromDataReader( dataReader );
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetSYS_UserEmpl:" + ex.Message);
			return null;
		}
	}
	
	public bool DelSYS_UserEmpl()
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "delete From SYS_UserEmpl where ";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("DelSYS_UserEmpl:" + ex.Message);
			return false;
		}
	}
	
	public bool UpdateSYS_UserEmpl(SYS_UserEmpl theSYS_UserEmpl)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "update SYS_UserEmpl set UserName=@UserName,EmplID=@EmplID where ";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@UserName", DbType.String, theSYS_UserEmpl.UserName);
			db.AddInParameter(cmd, "@EmplID", DbType.String, theSYS_UserEmpl.EmplID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("UpdateSYS_UserEmpl:" + ex.Message);
			return false;
		}
	}
	
	public List<SYS_UserEmpl> ListSYS_UserEmpl()
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * from SYS_UserEmpl";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			 List<SYS_UserEmpl> result = new  List<SYS_UserEmpl>();
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				while (dataReader.Read())
				{
					SYS_UserEmpl obj = GetSYS_UserEmplFromDataReader( dataReader );
					if(obj != null)
						result.Add(obj);
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("ListSYS_UserEmpl:" + ex.Message);
			return null;
		}
	}
	
}
#endregion